export let vertexSHADER = `
attribute vec4 a_Position;
void main(){
    vec4 posi=a_Position; 
    gl_Position=posi;
}
`
export let fragmentSHADER = `
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_Sampler;
uniform sampler2D u_Sampler1;
uniform sampler2D u_Sampler2;

uniform float isMobileF;

uniform vec4 dataRange;
uniform float u_Scale;
uniform float u_Startlon;
uniform float u_Startlat;

uniform float pic_width;
uniform float pic_height;

uniform float leftlon;
uniform float lonspan;
uniform vec2 widhei;

uniform float _Alpha;
uniform float minValue;
uniform float maxValue;

void main(){
    float lon=leftlon+lonspan*(gl_FragCoord.x/widhei.x);
    float trueLon=lon;
    lon=mod(lon,360.);
    if(lon<0.){
        lon=lon+360.;
    }
    
    vec2 texturecoor=vec2(0.,gl_FragCoord.y/widhei.y);
    vec4 color1=texture2D(u_Sampler1,texturecoor);
    float lat=color1.x*255.+color1.y*2.55+color1.z*.0255;
    if(color1.w>0.){
        lat=lat*-1.;
    }
    
    vec2 v_Lonlat=vec2(lon,lat);
    float col_left=float(floor((lon-u_Startlon)/u_Scale));
    float col_right=col_left+1.;
    float row_top=float(floor((u_Startlat-lat)/u_Scale));
    float row_bottom=row_top+1.;
    
    float left_p=col_left/pic_width;
    float right_p=col_right/pic_width;
    float top_p=1.-(row_top/pic_height);
    float bottom_p=1.-(row_bottom/pic_height);
    
    vec4 color_lt=texture2D(u_Sampler,vec2(left_p,top_p));
    vec4 color_rt=texture2D(u_Sampler,vec2(right_p,top_p));
    vec4 color_lb=texture2D(u_Sampler,vec2(left_p,bottom_p));
    vec4 color_rb=texture2D(u_Sampler,vec2(right_p,bottom_p));
    
    float val_lt=color_lt.x;
    float val_rt=color_rt.x;
    float val_lb=color_lb.x;
    float val_rb=color_rb.x;
    
    vec2 left_top=vec2(u_Startlon+u_Scale*col_left,u_Startlat-u_Scale*row_top);
    vec2 right_top=vec2(u_Startlon+u_Scale*col_right,u_Startlat-u_Scale*row_top);
    vec2 left_bottom=vec2(u_Startlon+u_Scale*col_left,u_Startlat-u_Scale*row_bottom);
    vec2 right_bottom=vec2(u_Startlon+u_Scale*col_right,u_Startlat-u_Scale*row_bottom);
    float rbxlbx=right_bottom.x-left_bottom.x;
    float rbxvx=right_bottom.x-v_Lonlat.x;
    if(rbxvx<=0.){
        rbxvx=0.;
    }
    if(rbxvx>=rbxlbx){
        rbxvx=rbxlbx;
    }
    float vxlbx=0.;
    vxlbx=rbxlbx-rbxvx;
    float r_1=rbxvx/rbxlbx*val_lb+vxlbx/rbxlbx*val_rb;
    float r_2=rbxvx/rbxlbx*val_lt+vxlbx/rbxlbx*val_rt;
    float ltylby=left_top.y-left_bottom.y;
    float ltyvy=left_top.y-v_Lonlat.y;
    if(ltyvy<=0.){
        ltyvy=0.;
    }
    if(ltyvy>=ltylby){
        ltyvy=ltylby;
    }
    float vylby=0.;
    vylby=ltylby-ltyvy;
    
    float v_12=ltyvy/ltylby*r_1+vylby/ltylby*r_2;
    vec4 necolor=vec4(0.,0.,0.,0.);
    // if(isMobileF==1.){
        //     necolor=texture2D(u_Sampler2,vec2(0.,1.-(val_lt-minValue)/(maxValue-minValue)));
    // }else{
        //     necolor=texture2D(u_Sampler2,vec2(0.,1.-(v_12-minValue)/(maxValue-minValue)));
    // }
    if(isMobileF==1.){
        necolor=texture2D(u_Sampler2,vec2(0.,1.-(val_lt-minValue)/(maxValue-minValue)));
    }else{
        necolor=texture2D(u_Sampler2,vec2(0.,1.-(val_lt-minValue)/(maxValue-minValue)));
    }
    
    necolor.w=_Alpha;
    if(lon<dataRange.z||lon>dataRange.w||lat<dataRange.y||lat>dataRange.x){
        necolor=vec4(0.,0.,0.,0.);
    }
    if(color_lt.x<-900.){
        necolor=vec4(0.,0.,0.,0.);
    }
    gl_FragColor=necolor;
}
`